package com.gao.weblog.web.config;

import org.springframework.amqp.core.*;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.gao.weblog.web.constant.RabbitConst.*;



@Configuration
public class RabbitMQConfig {

    @Bean
    public Jackson2JsonMessageConverter jackson2JsonMessageConverter() {
        return new Jackson2JsonMessageConverter();
    }


    @Bean
    public DirectExchange exchange(){
        return ExchangeBuilder.directExchange(READ_NUM_EXCHANGE).durable(true).build();
    }

    @Bean
    public Queue queue(){
        return QueueBuilder.durable(READ_NUM_QUEUE).build();
    }

    @Bean
    public Binding binding(){
        return BindingBuilder.bind(queue()).to(exchange()).with(READ_NUM_ROUTING);
    }


}
